#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import yaml

from oriolus.pith.packets.meta import Meta

class FileMetaReaderError(Exception):
    def __init__(self, message):
        Exception.__init__(self, message)

class MetaReader:
    def read(self, file):
        dict = yaml.load(file)

        return Meta(dict["name"], dict["version"], dict["description"], dict["conflicts"], dict["replaces"], dict["depends"])

class FileMetaReader:
    def __init__(self):
        self.__file_reader = MetaReader()

    def read(self, file_name):
        fd = None
        try:
            fd = file(file_name, "r")
            temp = self.__file_reader.read(fd)
        except Exception, error:
            raise FileMetaReaderError(error.message)            
        finally:
            if fd: fd.close()

        return temp